/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Server;

/**
 *
 * @author Rebecca
 */
// File Name GreetingClient.java

import java.io.*;
import java.net.Socket;

public class Client
{
//   public static void main(String [] args)
//   {
//      String serverName = args[0];
//      int port = Integer.parseInt(args[1]);
//      try
//      {
//         System.out.println("Connecting to " + serverName
//                             + " on port " + port);
//         Socket client = new Socket(serverName, port);
//         System.out.println("Just connected to "
//                      + client.getRemoteSocketAddress());
//         OutputStream outToServer = client.getOutputStream();
//         DataOutputStream out =
//                       new DataOutputStream(outToServer);
//
//         out.writeUTF("Hello from "
//                      + client.getLocalSocketAddress());
//         InputStream inFromServer = client.getInputStream();
//         DataInputStream in =
//                        new DataInputStream(inFromServer);
//         System.out.println("Server says " + in.readUTF());
//         client.close();
//      }catch(IOException e)
//      {
//         e.printStackTrace();
//      }
//   }
   
      public void connectServer(String sName, String p, String data)
   {
      String serverName = sName;
      int port = Integer.parseInt(p);
      try
      {
         System.out.println("Connecting to " + serverName
                             + " on port " + port);
         Socket client = new Socket(serverName, port);
         System.out.println("Just connected to "
                      + client.getRemoteSocketAddress());
         OutputStream outToServer = client.getOutputStream();
         DataOutputStream out =
                       new DataOutputStream(outToServer);

//         out.writeUTF("Hello from "
//                      + client.getLocalSocketAddress());
         out.writeUTF(data);
         InputStream inFromServer = client.getInputStream();
         DataInputStream in =
                        new DataInputStream(inFromServer);
         System.out.println("Server says " + in.readUTF());
         client.close();
      }catch(IOException e)
      {
         e.printStackTrace();
      }
   }
}